ListNode* reverseBetween(ListNode* head, int left, int right) {
        ListNode *dummy = new ListNode(-1);
        dummy->next = head;

        ListNode *pre = dummy;
        for(int i = 1; i < left; ++i)
            pre = pre->next;
        
        ListNode *cur = pre->next, *next; 
        for(int i = left; i < right; ++i)
        {
            next = cur->next;
            cur->next = next->next;
            next->next = pre->next;
            pre->next = next;  
        }
        return dummy->next;

    }